/*
 *Copyright (c) 2024 Black Sesame Technologies
 *
 *Licensed under the Apache License, Version 2.0 (the "License");
 *you may not use this file except in compliance with the License.
 *You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *Unless required by applicable law or agreed to in writing, software
 *distributed under the License is distributed on an "AS IS" BASIS,
 *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *See the License for the specific language governing permissions and
 *limitations under the License.
*/
 
/*  
 *  VERSION :
 *  Autosar Version      : 4.4.0
 *  SW Version           : 1.0.0
*/
#ifndef VCAN_COMMAND_H
#define VCAN_COMMAND_H

/**
*   @file    VCan_Command.h
*   @version 1.0.0
*
*   @brief   AUTOSAR VCan - module interface.
*   @details API header for VCAN driver.
*
*   @addtogroup VCAN_DRIVER
*   @{
*/
#ifdef __cplusplus
extern "C"{
#endif
/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "../hscg_flexcan/StandardTypes.h"



/*==================================================================================================
*                          LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/

/** 数据相关结构体 */
typedef struct {
    uint32 timestamp : 16;
    uint32 dlc : 4;
    uint32 rtr : 1;
    uint32 ide : 1;
    uint32 srr : 1;
    uint32 rsvd : 6;
    uint32 esi : 1;
    uint32 brs : 1;
    uint32 edl : 1;  //4Byte
    uint32 id;       //4Byte
    uint8 param[56]; //56Byte
    uint8 data[64];  //64Byte
} CAN2X;         //共计128Byte

typedef struct
{
    uint8 CAN2ETH_DMAC[6];  //6Byte
    uint8 rsvd0[2];    //2Byte

    uint32 src_can_bus_id : 4;
    uint32 filter_id : 8;
    uint32 rsvd1 : 20;   //4Byte

    uint32 gmac_timestamp_second_h;
    uint32 gmac_timestamp_second_l;
    uint32 gmac_timestamp_nanosecond;  //12Byte

    uint8 rsvd2[32];
} CAN2X_PARAMS;   //共计56B，对应上述的 param[56]


/**
 * ETH2CAN、AUTOSAR2CAN、SST2CAN等结构体
*/
typedef struct {
    uint32 rsvd0: 16;         //保留，填0
    uint32 dlc : 4;           //dlc，can实际数据长度.注:dlc=9,并不代表数据长度为9，请百度can dlc
    uint32 rtr : 1;           //是否为can远程帧
    uint32 ide : 1;           //是否为can扩展帧
    uint32 srr : 1;           //保留，填0
    uint32 rsvd1 : 6;         //保留，填0
    uint32 esi : 1;           //是否为错误帧，绝大部分情况下填0
    uint32 brs : 1;           //是否为canfd加速帧
    uint32 edl : 1;           //是否为canfd帧
    uint32 id;                //canid
    uint8 param[56];          //56Byte的额外参数，具体结构为下列的X2CAN_PARAMS
    uint8 data[64];           //can报文携带的的实际数据
} X2CAN;

typedef struct 
{
    uint32 client_id;           //预留，暂时非必填，vcan_client id用于下行方向路由表
    uint32 timestamp_l;         //预留，暂时非必填
    uint32 timestemp_h;         //预留，暂时非必填
    uint32 des_can_bus_id : 4;  //从哪个can通道发送出去, 下个版本会删除此字段。
    uint32 rsvd0 : 28;          //保留，填0
    uint8 rsvd1[40];            //保留，填0
} X2CAN_PARAMS;   //共计56B，对应上述的 param[56]


typedef enum
{
    LLCG_COMMAND_INIT_DONE       = 0,
    LLCG_COMMAND_SET_CONTROLLER  = 1,  //告诉VCAN核，有哪些Controller用于VCAN
    LLCG_COMMAND_INIT_BASE_ROUTE_TABLE = 2,    //告诉VCAN核，base路由表的位置，VCAN核先自己复制一份
    LLCG_COMMAND_INIT_COMMON_ROUTE_TABLE = 3,  //告诉VCAN核，common路由表的位置，VCAN核先自己复制一份
    LLCG_COMMAND_SET_ROUTE_TABLE = 4,  //告诉VCAN核，Controller+filter对应的转发规则
}LLCG_COMMAND_ENUM;

typedef struct
{
    uint32 can_controller_id; //用于vcan的controller编号，范围0~16
}LLCG_COMMAND_PARAM_SET_CONTROLLER;


typedef struct
{
    uint32 base_route_table_ptr; //指向LLCG_RouteTableBase
    uint32 base_route_table_size;

}LLCG_COMMAND_PARAM_INIT_BASE_ROUTE_TABLE;

typedef struct
{
    uint8 can_controller_id;
    uint32 common_route_table_ptr;
    uint32 common_route_table_size;
}LLCG_COMMAND_PARAM_INIT_COMMON_ROUTE_TABLE;



typedef struct
{
    uint32 can_controller_id;
    uint32 filter_id;
    uint32 fast_route_table_ptr;
    uint32 common_route_table_ptr;
}LLCG_COMMAND_PARAM_SET_ROUTE_TABLE;



#ifdef __cplusplus
}
#endif

#endif /* VCAN_COMMAND_H */
